import { getTeApiData } from '@/services/cpasRequest';
import { intl } from '@/utils';
import Form, { Item } from 'devextreme-react/form';
import { useCallback, useEffect, useState } from 'react';
import { getStackStatus } from '../../tools';
import { getListData } from '../service';
import './index.less';

const ZcbfForm = (props: any) => {
  const { tableRow } = props;
  const [formData, setFormData] = useState<any>({});

  const getFormData = useCallback(async () => {
    const res = await getListData({ projectBh: tableRow.projectBh });
    if (res.success) {
      const resTe = await getTeApiData({ projectBh: tableRow.projectBh });
      const resTempData = res.data.length > 0 ? res.data[0] : {};
      const resData = {
        ...res,
        data: [
          {
            ...resTempData,
            ...resTe.data,
          },
        ],
      };
      const tempData = getStackStatus(resData.data[0].projectState);
      setFormData({ ...resData.data[0], projectState: tempData });
    }
  }, [tableRow]);

  useEffect(() => {
    if (tableRow.projectBh) {
      getFormData();
    } else {
      setFormData({});
    }
  }, [tableRow, getFormData]);

  return (
    <div className="ZcbfFormClass">
      <Form
        formData={formData}
        showColonAfterLabel={true}
        labelLocation="left"
        // labelMode='floating'
      >
        <Item
          dataField="projectBh"
          label={{
            text: intl('pro.DataGrid.ProjectNumber', '项目编号'),
          }}
          editorOptions={{ width: '100%', disabled: true }}
        />
        <Item
          dataField="projectName"
          label={{
            text: intl('pro.DataGrid.ProjectNumber', '项目名称'),
          }}
          editorOptions={{ width: '100%', disabled: true }}
        />
        <Item
          dataField="bsdw"
          label={{
            text: intl('pro.DataGrid.ProjectNumber', '被审单位'),
          }}
          editorOptions={{ width: '100%', disabled: true }}
        />
        <Item
          dataField="bsdwxydm"
          label={{
            text: intl('pro.DataGrid.ProjectNumber', '被审计单位企业信用代码'),
          }}
          editorOptions={{ width: '100%', disabled: true }}
        />
        <Item
          dataField="sjdwxydm"
          label={{
            text: intl('pro.DataGrid.ProjectNumber', '上级单位企业信用代码'),
          }}
          editorOptions={{ width: '100%', disabled: true }}
        />
        <Item
          dataField="jtgsxydm"
          label={{
            text: intl('pro.DataGrid.ProjectNumber', '集团公司企业信用代码'),
          }}
          editorOptions={{ width: '100%', disabled: true }}
        />
        <Item
          dataField="projectState"
          label={{
            text: intl('pro.DataGrid.ProjectNumber', '项目状态'),
          }}
          editorOptions={{ width: '100%', disabled: true }}
        />
        <Item
          dataField="sjnd"
          label={{
            text: intl('pro.DataGrid.ProjectNumber', '审计年度'),
          }}
          editorOptions={{ width: '100%', disabled: true }}
        />

        <Item
          dataField="xmTimeStart"
          label={{
            text: '会计期间开始',
          }}
          editorType="dxDateBox"
          editorOptions={{ width: '100%', disabled: true }}
        />
        <Item
          dataField="xmTimeEnd"
          label={{
            text: '会计期间结束',
          }}
          editorType="dxDateBox"
          editorOptions={{ width: '100%', disabled: true }}
        />

        <Item
          dataField="manager"
          label={{
            text: intl('pro.DataGrid.ProjectNumber', '项目经理'),
          }}
          editorOptions={{ width: '100%', disabled: true }}
        />
        <Item
          dataField="xmhhr"
          label={{
            text: intl('pro.DataGrid.ProjectNumber', '项目合伙人'),
          }}
          editorOptions={{ width: '100%', disabled: true }}
        />
      </Form>
    </div>
  );
};

export default ZcbfForm;
